package org.xingole.cookbook;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.api.Git;

/**
 * Simple snippet which shows how to create a new repository
 * 
 * @author Xingole Jankins
 */
public class CreateNewRepository {
    public static void main(String[] args) throws IOException {
        // prepare a new folder
        File localPath = File.createTempFile("TestGitRepository", "");
        if(!localPath.delete()) {
            throw new IOException("Could not delete temporary file" + localPath);
        }

        // create the directory
        try (Git git = Git.init().setDirectory(localPath).call()) {
            System.out.println("Having repository: " + git.getRepository().getDirectory());
        } catch (Exception e) {
            e.printStackTrace();
        }

        // clean up here to not keep using more and more disk-space for these samples
        FileUtils.deleteDirectory(localPath);
    }
}
